package com.edou.member.controller.member;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.edou.base.constant.SessionConstant;
import com.edou.base.controller.BaseController;
import com.edou.member.entity.MemberUser;
import com.edou.member.service.IMemberRightService;
import com.edou.member.service.IMemberUserService;

/**
 * 会员首页模块
 * @creator     admin
 * @create-time 2016/3/12 16:10:22
 * @email admin@edou.com
 * @company www.edou.com
 * @version 1.0
 */
@Controller("memberIndexController")
@Scope("prototype")
@RequestMapping("/member")
public class MemberIndexController extends BaseController {

	@Resource(name = "memberUserServiceImpl")
	private IMemberUserService memberUserService;
	@Resource(name = "memberRightServiceImpl")
	private IMemberRightService memberRightService;
	
	/**
	 * 跳转到首页
	 * @return 
	 */
	@RequestMapping(value = "/index.htm", method = RequestMethod.GET)
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response,HttpSession session){
		MemberUser member = (MemberUser)session.getAttribute(SessionConstant.CURRENT_MEMBER);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/member/index/index");
		Map<String, Object> data = modelAndView.getModel();
		//构造用户权限JSON数据
		String rightJsonStr = memberRightService.buildUserRightJSONStr(member);
//		List<Right> rights = rightService.buildUserRights(member);
		data.put(SessionConstant.CURRENT_PRIVILEGE, rightJsonStr);
		data.put("member", member);
		return modelAndView;
	}
	
	/**
	 * 临时方法：跳转到忘记密码-修改密码页面
	 * @return 
	 */
	@RequestMapping(value = "/test_forget_pwd.htm", method = RequestMethod.GET)
	public String testForgetPwd(){
		return "/member/login/forget_email_edit_pwd";
	}
	
	/**
	 * 临时方法：跳转到忘记密码-修改密码成功页面
	 * @return 
	 */
	@RequestMapping(value = "/test_forget_pwd_success.htm", method = RequestMethod.GET)
	public String testForgetPwdSuccess(){
		return "/member/login/forget_email_edit_success";
	}
	
	
	
}